<?php
/**
 * 产品类型的相关操作
 * @author:zhulin
 * @since:2012 5.9
 */
class ProductController extends  baseController{
    /**
     * 产品列表页的显示
     */
     public function getCat(){ 
        $TId = empty( $_GET['TId'] )?NULl:$this->getParamInt( 'TId' , false , $isGet = true );
        $FId = empty( $_GET['FId'] )?NULL:$this->getParamInt( 'FId' , false , $isGet = true );
        $BId = empty( $_GET['BId'] )?NUll:$this->getParamInt( 'BId' , false , $isGet = true );
        $LId = empty( $_GET['LId'] )?NULL:$this->getParamInt( 'LId' , false , $isget = true );
        $SId = empty( $_GET['SId'] )?NULL:$this->getParamInt( 'SId' , false , $isget = true );
        $AId = empty( $_GET['AId'] )?NULL:$this->getParamInt( 'AId' , false , $isget = true );
        /**
         * 类型的显示
         */
        $_type = Category_Show::getInstance()->_getCategory( $TId , $FId );  
        
        $type = Category_Show::getInstance()->getCategory( $TId , $FId);
         
        //根据产品品牌查询产品小类
        $BrandArr = Brand_Search::getInstance()->getSCatByBrand( $BId );
        /**
         * 产品列表显示
         */
        //根据产品的品牌查询产品
        if( !empty( $BId )){
            $productInfo = Product_Info::getInstance()->getProductInfoByBrand( $BId );  
        }
        //根据产品消费层次查询产品
        elseif( !empty( $LId ) ){
            $productInfo = Product_Info::getInstance()->getProductInfoByLevel( $TId , $LId ); 
        }
        //根据性别查询产品
        elseif( !empty( $SId)){
            $productInfo = Product_Info::getInstance()->getProductInfoBySex( $TId , $SId );
        }
        elseif( !empty( $AId )){
             $productInfo = Product_Info::getInstance()->getProductInfoByAge( $TId , $AId );
        }
        //根据产品类型查询产品
        else{
            $productInfo = Product_Info::getInstance()->getProductInfoByCat( $TId ); 
        }
        //根据产品
        
        /**
         *  产品筛选选项的显示
         */
        /**
         * 对产品品牌的筛选
         *  
         */
        //根据BId 查找小类：

        $productBrand = Brand_Search::getInstance()->getProductBrand( $TId  );
        //消费层次
        $level = dimensions_Info::getinstance()->getDim();
        //适用性别
        $sex = dimensions_Info::getinstance()->getSex();
        //适用年龄段
        $age= dimensions_Info::getinstance()->getAge();
        
        /**
         * 浏览历史记录
         */
        if ( isset( $_COOKIE['ProductInfo'] ) ) {
                    $arrCookie = unserialize( $_COOKIE['ProductInfo'] );
                    $productHistory = Product_Info::getinstance()->getProductHistory( $arrCookie );
              }
        include TPL_DIR.'category.php'; 
        
    }
    /**
     * 获得产品详细信息
     */
    public function getDetail(){
        $PId = $this->getParamInt( 'PId' , false , $isGet = true );
        $BCat = $this->getParamInt( 'BCat' , false , $isGet=true);
        $SCat = $this->getParamInt( 'SCat' , false , $isGet=true);
        /**
         * 分类
         */
        $_type = Category_Show::getInstance()->_getCategory( $BCat  );
       
        $type = Category_Show::getInstance()->getCategory( $BCat ); 
        
        /**
         * 产品详细信息
         */
        $productDetail = Product_Info::getInstance()->getProductDetail( $PId );
        /**
         * 记录产品的Cookie 和session
         */
             Product_Info::getInstance()->saveToCookieSession( $productDetail );
             //历史浏览记录
              if ( isset( $_COOKIE['ProductInfo'] ) ) {
                    $arrCookie = unserialize( $_COOKIE['ProductInfo'] );
                    $productHistory = Product_Info::getinstance()->getProductHistory( $arrCookie );
              }
          /**
           * 用户登录记录redis未登录记录cookie
           */
              if( isset( $_SESSION['UId'])){
                  User_like::getInstance()->saveToRedis($productDetail['PId'] );
              }
              
              else{
                  User_like::getInstance()->saveToCookie($productDetail['PId'] );  
              }
          
         include TPL_DIR.'goods.php'; 
    }
  
 
    
    
    
}